
package CSS::Preprocessor::Token::Number;

use strict;
use base qw(CSS::Preprocessor::Token);
use fields qw(
    value
    unit
);

sub new {
    my ($class, $value, $unit) = @_;

    my $self = $class->CSS::Preprocessor::Token::new();
    $self->{value} = $value;
    $self->{unit} = $unit;

    return $self;
}

sub value {
    return $_[0]->{value};
}

sub unit {
    return $_[0]->{unit};
}

sub is_dimension {
    my $self = shift;

    # Zero without a unit is a valid dimension
    return 1 if $self->value == 0;

    # Any other unit that isn't a percentage is a dimension
    return 1 if $self->unit && $self->unit ne '%';

    return 0;
}

sub is_percentage {
    return $_[0]->unit eq '%' ? 1 : 0;
}

sub is_bare_number {
    return $_[0]->unit ? 0 : 1;
}

sub as_string_inner {
    return $_[0]->{value}.($_[0]->{unit} || '');
}

1;

